<?php

namespace yiike\company\model;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use yiike\company\model\TtycStore;

/**
* TtycStoreSearch represents the model behind the search form about `yiike\company\model\TtycStore`.
*/
class TtycStoreSearch extends TtycStore
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'weid', 'uid', 'cityid', 'type', 'pcate', 'ccate', 'level', 'isfirst', 'top', 'mode', 'checked', 'status', 'displayorder', 'updatetime', 'isvip', 'vip_start', 'vip_end', 'max_sub', 'maker_id', 'company_id', 'commission_rate'], 'integer'],
            [['wx_mchid', 'alipay_mchid', 'title', 'description', 'logo', 'images', 'services', 'username', 'tel', 'address', 'discounts', 'consume', 'place', 'hours', 'starttime', 'endtime', 'location_p', 'location_c', 'location_a', 'from_user', 'businesslicense', 'bank', 'bank_sub', 'payee', 'bank_account','checked'], 'safe'],
            [['lat', 'lng', 'shop_quan_rate', 'combo'], 'number'],
];
}

/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}

/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = TtycStore::find();

$dataProvider = new ActiveDataProvider([
'query' => $query,
]);

$this->load($params);

if (!$this->validate()) {
// uncomment the following line if you do not want to any records when validation fails
// $query->where('0=1');
return $dataProvider;
}

$query->andFilterWhere([
            'id' => $this->id,
            'weid' => $this->weid,
            'uid' => $this->uid,
            'cityid' => $this->cityid,
            'type' => $this->type,
            'pcate' => $this->pcate,
            'ccate' => $this->ccate,
            'level' => $this->level,
            'lat' => $this->lat,
            'lng' => $this->lng,
            'isfirst' => $this->isfirst,
            'top' => $this->top,
            'mode' => $this->mode,
            'checked' => $this->checked,
            'status' => $this->status,
            'displayorder' => $this->displayorder,
            'updatetime' => $this->updatetime,
            'dateline' => $this->dateline,
            'isvip' => $this->isvip,
            'vip_start' => $this->vip_start,
            'vip_end' => $this->vip_end,
            'max_sub' => $this->max_sub,
            'maker_id' => $this->maker_id,
            'company_id' => $this->company_id,
            'commission_rate' => $this->commission_rate,
            'shop_quan_rate' => $this->shop_quan_rate,
            'combo' => $this->combo,
        ]);

        $query->andFilterWhere(['like', 'wx_mchid', $this->wx_mchid])
            ->andFilterWhere(['like', 'alipay_mchid', $this->alipay_mchid])
            ->andFilterWhere(['like', 'title', $this->title])
            ->andFilterWhere(['like', 'description', $this->description])
            ->andFilterWhere(['like', 'logo', $this->logo])
            ->andFilterWhere(['like', 'images', $this->images])
            ->andFilterWhere(['like', 'services', $this->services])
            ->andFilterWhere(['like', 'username', $this->username])
            ->andFilterWhere(['like', 'tel', $this->tel])
            ->andFilterWhere(['like', 'address', $this->address])
            ->andFilterWhere(['like', 'discounts', $this->discounts])
            ->andFilterWhere(['like', 'consume', $this->consume])
            ->andFilterWhere(['like', 'place', $this->place])
            ->andFilterWhere(['like', 'hours', $this->hours])
            ->andFilterWhere(['like', 'starttime', $this->starttime])
            ->andFilterWhere(['like', 'endtime', $this->endtime])
            ->andFilterWhere(['like', 'location_p', $this->location_p])
            ->andFilterWhere(['like', 'location_c', $this->location_c])
            ->andFilterWhere(['like', 'location_a', $this->location_a])
            ->andFilterWhere(['like', 'from_user', $this->from_user])
            ->andFilterWhere(['like', 'businesslicense', $this->businesslicense])
            ->andFilterWhere(['like', 'bank', $this->bank])
            ->andFilterWhere(['like', 'bank_sub', $this->bank_sub])
            ->andFilterWhere(['like', 'payee', $this->payee])
            ->andFilterWhere(['like', 'bank_account', $this->bank_account]);

return $dataProvider;
}
}